package mj.scott.back.exam.service.impl;

import lombok.extern.slf4j.Slf4j;
import mj.scott.back.exam.mapper.ExamMapper;
import mj.scott.back.exam.pojo.dto.ExamQuery;
import mj.scott.back.exam.pojo.dto.ExamSaveParam;
import mj.scott.back.exam.pojo.entity.Exam;
import mj.scott.back.exam.pojo.vo.ExamVO;
import mj.scott.back.exam.service.ExamService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Slf4j
@Service
public class ExamServiceImpl implements ExamService {
    @Autowired
    ExamMapper examMapper;
    @Override
    public List<ExamVO> select(ExamQuery query) {
        log.debug("【业务层】【查询考试列表】{}", query);
        List<ExamVO> vo = examMapper.select(query);
        return vo;
    }

    @Override
    public void saveExam(ExamSaveParam param) {
        log.debug("【业务层】【保存考试】{}", param);
        Exam exam = new Exam();
        BeanUtils.copyProperties(param, exam);
        //TODO 根据时间设置考试状态
        if (exam.getExamId() == null) {//新增考试
            exam.setStatus("0");
            examMapper.inset(exam);
        } else {//更新考试
            exam.setStatus("1");
            examMapper.update(exam);
        }
    }

    @Override
    public void deleteExam(Long examId) {
        log.debug("【业务层】【删除考试】{}", examId);
        examMapper.delete(examId);
    }
}
